package domain

import (
	"github.com/lab-online/internal/shared/code"
	"github.com/lab-online/internal/user/entity"
)

func (d *Domain) DeleteUser(user entity.UserEntity) error {
	if savedUser, err := d.repository.GetUserByUsername(user.GetUsername()); err != nil {
		return code.ErrorPicker(err, code.DatabaseUserNotFound, nil)
	} else {
		// TODO: 使用消息队列或事件总线发布用户删除事件
		return d.repository.DeleteUser(savedUser)
	}
}
